package com.daohang361.imqq.pugin.decoder;

import org.apache.mina.core.session.IoSession;

import com.daohang361.imqq.Asycore.Connector;
import com.daohang361.imqq.Asycore.QQUser;
import com.daohang361.imqq.decoder.InterfaceDecoder;
import com.daohang361.imqq.encoder.InterfaceEncoder;
import com.daohang361.imqq.hotLoader.PuginManager;
import com.daohang361.imqq.tool.Hex2Bytes;
import com.daohang361.imqq.tool.MyByteReciveArray;

/** 
 * @author naner E-mail:likun3344@163.com 
 * @create time：2011-6-7 下午11:06:20 
 */
public class Decoder36  implements InterfaceDecoder{
	public MyByteReciveArray myArray;
	public QQUser sessionQQ;
	public byte[] decryptAll=null;
	@Override
	public void init(MyByteReciveArray myArray, QQUser sessionQQ) {
		this.myArray=myArray;
		this.sessionQQ=sessionQQ;
	}
	@Override
	public QQUser decode() throws Exception {
		myArray.extract(0, 4);
		myArray.decryptRemain(sessionQQ.getAttr("imgKey"));
		byte[] token_data_36 = myArray.extractAll();
		sessionQQ.addAttr("token_data_36", token_data_36);
		System.out.println("token_data_36:"+Hex2Bytes.bytesToHexString(token_data_36));
		sessionQQ.setCommand(0);//0:不回复,即HexEncodeProtocol失效,大于0:则为encoder执行命令
		
		QQUser newqq =sessionQQ;
		Connector Myconnector = new Connector();
		IoSession newSession = Myconnector.CreateSession("124.115.12.194", 8000);		
		InterfaceEncoder encoderAC = ((InterfaceEncoder) PuginManager.GetPuginByKey("EncoderAC"));
		byte[] temp=encoderAC.encode(newqq, 0xac);
		newqq.setCommand(0xac);
		newqq.addDirectSendByte(temp);
		newSession.write(newqq);
		
		return sessionQQ;
	}
	
	/**
	 * 暴力打印
	 */
	public void violence()
	{
		//new ViolenceBytes(decryptAll).violence();
	}

	@Override
	public Object invoke(Object... o) {
		// TODO Auto-generated method stub
		return null;
	}
}
